import axios from 'axios'
// 配置请求的根路径
// const qiaofinnUrl = 'http://127.0.0.1:8900/'
const qiaofinnUrl = 'https://qiaofinn.com/'
axios.defaults.baseURL = qiaofinnUrl
// 通过axios请求拦截器添加token
axios.interceptors.request.use(config => {
  // console.log(config)
  config.headers.Authorization = 'JWT ' + window.sessionStorage.getItem('token')
  return config
})
// upload
export function getUploadParamsApi(savePath) {
  return {
    uploadFileUrl: qiaofinnUrl + 'system/upload/',
    uploadHeaders: {
      Authorization: 'JWT ' + window.sessionStorage.getItem('token')
    },
    uploadData: {
      savePath: savePath
    }
  }
}

// 测试
export function getCouponsTestList(data) {
  return axios.get('coupons/', {
    params: data
  })
}
// 登录
export function _loginApi(data) {
  return axios.post('account/login/', data)
}
// 获取menu数据
export function _menuApi() {
  return axios.get('system/menu/')
}
// 文章
// 1.获取关联文章
export function getRelateArticleApi() {
  return axios.get('article/relate/')
}
export function _getArticleListApi(data) {
  return axios.get('article/', {
    params: data
  })
}
export function _getArticleDetailApi(id) {
  return axios.get('article/' + id + '/')
}
export function _updateOrCreateArticleApi(formData, operate) {
  return operate === 'add' ? axios.post('article/', formData) : axios.put('article/' + formData.id + '/',
    formData)
}
// 装修百科
export function getAdornPediaDictApi() {
  return axios.get('adorn_pedia/dict/')
}
export function getAdornPediaListApi(data) {
  return axios.get('adorn_pedia/', {
    params: data
  })
}
// 关联产品
export function _adornPediaRelectProductApi(id, relateValue) {
  return axios.post('adorn_pedia/' + id + '/relate_products/', relateValue)
}
export function _getAdornPediaDetailApi(id) {
  return axios.get('adorn_pedia/' + id + '/')
}
export function deleteAdornPediaApi(id) {
  return axios.delete('adorn_pedia/' + id + '/')
}
export function updateOrCreateAdornPediaApi(formData, operate) {
  return operate === 'add' ? axios.post('adorn_pedia/', formData) : axios.put('adorn_pedia/' + formData.id + '/',
    formData)
}
export function _addPediaImageApi(id, imageId) {
  return axios.post('adorn_pedia/' + id + '/add_images/', {
    imageId: imageId
  })
}
export function _addPediaContentImageApi(id, imageId) {
  return axios.post('adorn_pedia/' + id + '/add_content_images/', {
    imageId: imageId
  })
}
// ##########################装修流程 start#################################
export function getAdornProcessListApi(data) {
  return axios.get('adorn_process/', {
    params: data
  })
}
export function deleteAdornProcessApi(id) {
  return axios.delete('adorn_process/' + id + '/')
}
export function updateOrCreateAdornProcessApi(formData, operate) {
  return operate === 'add' ? axios.post('adorn_process/', formData) : axios.put('adorn_process/' + formData.id + '/',
    formData)
}
// 关联文章
export function adornProRelectArticleApi(id, relateValue) {
  return axios.post('adorn_process/' + id + '/relate_article/', relateValue)
}
// ##########################装修流程 end#################################

// ##########################装修案例 house start#################################
export function getProjectCaseListApi(data) {
  return axios.get('project_case/house/', {
    params: data
  })
}
export function getHouseApi(houseId) {
  return axios.get('project_case/house/' + houseId + '/')
}
export function deleteProjectCaseApi(id) {
  return axios.delete('project_case/house/' + id + '/')
}
export function updateOrCreateProjectCaseApi(formData, operate) {
  return operate === 'add' ? axios.post('project_case/house/', formData) : axios.put('project_case/house/' + formData.id +
    '/',
    formData)
}
export function getProjectCaseDictApi(data) {
  return axios.get('project_case/dict/')
}
// 添加房间
export function _addHouseRoomApi(houseId, roomFormData) {
  return axios.post('project_case/house/' + houseId + '/add_room/', roomFormData)
}
// 删除房间
export function _delHouseRoomApi(roomId) {
  return axios.post('project_case/house/del_room/', {
    roomId: roomId
  })
}
// ##########################装修案例 house end#################################
// ##########################装修案例 room start#################################
export function getHouseRoomListApi(data) {
  return axios.get('project_case/room/', {
    params: data
  })
}
export function deleteHouseRoomApi(id) {
  return axios.delete('project_case/room/' + id + '/')
}
export function updateOrCreateHouseRoomApi(formData, operate) {
  return operate === 'add' ? axios.post('project_case/room/', formData) : axios.put('project_case/room/' + formData.id +
    '/',
    formData)
}
// ##########################装修案例 room end#################################

// ##########################产品 start#################################
export function getProductListApi(data) {
  return axios.get('product/', {
    params: data
  })
}
export function _getrelateProductListApi() {
  return axios.get('product/relate/')
}
export function getProductApi(productId) {
  return axios.get('product/' + productId + '/')
}
export function deleteProductApi(productId) {
  return axios.delete('product/' + productId + '/')
}
export function updateOrCreateProductApi(formData, operate) {
  return operate === 'add' ? axios.post('product/', formData) : axios.put('product/' + formData.id +
    '/',
    formData)
}
export function getProductDictApi(data) {
  return axios.get('product/dict/')
}
// 产品添加图片
export function addProductImageApi(productId, imageId) {
  return axios.post('product/' + productId + '/add_image/', {
    imageId: imageId
  })
}
// 产品详情添加图片
export function _addProductDetailImageApi(productId, imageId) {
  return axios.post('product/' + productId + '/add_detail_image/', {
    imageId: imageId
  })
}
// 添加产品属性
export function _addProductParameterApi(productId, parameterFormData) {
  return axios.post('product/' + productId + '/add_parameters/', parameterFormData)
}
export function _delProductParameterApi(productId, parameterId) {
  return axios.post('product/' + productId + '/del_parameters/', {
    parameterId: parameterId
  })
}
// ##########################产品  end#################################
// ##########################预约服务  start#################################
const adornServiceUrl = 'service/adorn_service/'
export function _getAdornServiceListApi(data) {
  return axios.get(adornServiceUrl, {
    params: data
  })
}
export function _getAdornServiceApi(id) {
  return axios.get(adornServiceUrl + id + '/')
}
export function _deleteAdornServiceApi(id) {
  return axios.delete(adornServiceUrl + id + '/')
}
export function _updateOrCreateAdornServiceApi(formData, operate) {
  return operate === 'add' ? axios.post(adornServiceUrl, formData) : axios.put(adornServiceUrl + formData.id +
    '/', formData)
}
// ##########################预约服务  end#################################
// ##########################系统管理  start#################################
const systemOptionUrl = 'system/option/'
export function _getSystemOptionListApi(data) {
  return axios.get(systemOptionUrl, {
    params: data
  })
}
export function _deleteSystemOptionApi(id) {
  return axios.delete(systemOptionUrl + id + '/')
}
export function _updateOrCreateSystemOptionApi(formData, operate) {
  return operate === 'add' ? axios.post(systemOptionUrl, formData) : axios.put(systemOptionUrl + formData.id +
    '/', formData)
}
export function _getSystemOptionDictApi(data) {
  return axios.get(systemOptionUrl + 'type_dict/')
}
// ##########################系统管理  end#################################
// ##########################工人  end#################################
export function _getWorkerListApi(queryParam) {
  return axios.get('worker/', {
    params: queryParam
  })
}
export function _getWorkerApi(workerId) {
  return axios.get('worker/' + workerId + '/')
}
export function _delWorkerApi(workerId) {
  return axios.delete('worker/' + workerId + '/')
}
export function _updateOrCreateWorkerApi(formData, operate) {
  return operate === 'add' ? axios.post('worker/', formData) : axios.put('worker/' + formData.id +
    '/', formData)
}
